/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package camada.apresentacao.dialog.veiculo;

import camada.apresentacao.dialog.banco.*;
import camada.bancodedados.conexao.Conexao;
import camada.bancodedados.daoimplemente.banco.BancoDAOImpl;
import camada.bancodedados.daoimplemente.contabancaria.ContaBancariaDAOImpl;
import combomodel.banco.ComboBoxBancoModel;
import eloma.classe.banco.Banco;
import eloma.classe.contabancaria.ContaBancaria;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import java.util.logging.Level;
import javax.swing.JOptionPane;
import javax.swing.border.Border;
import org.jdesktop.swingx.error.ErrorInfo;
import utilitarios.Exceptions;
import utilitarios.LimitarTamanhoTextField;
import utilitarios.erros.MessagemErro;

/**
 *
 * @author Ícaro
 */
public class InternalFrmCadVeiculo extends javax.swing.JInternalFrame {

    boolean ePesquisa = false;
    private static Connection con;
    Border border;
    Exceptions exceptions = new Exceptions();
    ContaBancariaDAOImpl daoContaBancaria = new ContaBancariaDAOImpl();
    BancoDAOImpl daoBanco = new BancoDAOImpl();
    List<ContaBancaria> listaContaBancaria;
    int index;
    boolean editar = false;

    /**
     * Creates new form internalFrmCadCliente
     */
    public InternalFrmCadVeiculo() {
        initComponents();
        carregarCombo();
        capturaDados();
        montarFields(index);
        border = txtNumeorConta.getBorder();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jScrollPane1 = new javax.swing.JScrollPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtRegistro = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txtAgencia = new javax.swing.JTextField();
        txtNumeorConta = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        cmBanco = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        sfDiaVencimento = new com.toedter.components.JSpinField();
        jToolBar1 = new javax.swing.JToolBar();
        btNaoSeiAinda = new org.jdesktop.swingx.JXHyperlink();
        btNovo = new org.jdesktop.swingx.JXHyperlink();
        btSalvar = new org.jdesktop.swingx.JXHyperlink();
        btEditar = new org.jdesktop.swingx.JXHyperlink();
        btExcluir = new org.jdesktop.swingx.JXHyperlink();
        btCancelar = new org.jdesktop.swingx.JXHyperlink();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        btPrimeiro = new org.jdesktop.swingx.JXHyperlink();
        btAnterior = new org.jdesktop.swingx.JXHyperlink();
        btProximo = new org.jdesktop.swingx.JXHyperlink();
        btUltimo = new org.jdesktop.swingx.JXHyperlink();
        jSeparator2 = new javax.swing.JToolBar.Separator();
        btPesquisa = new org.jdesktop.swingx.JXHyperlink();
        jXHyperlink12 = new org.jdesktop.swingx.JXHyperlink();
        jSeparator5 = new javax.swing.JToolBar.Separator();
        txtSair = new org.jdesktop.swingx.JXHyperlink();
        jSeparator4 = new javax.swing.JSeparator();

        setTitle("BANCO");
        setToolTipText("Cadastro Banco");

        jScrollPane1.setBorder(null);

        jPanel1.setToolTipText("Cadastro de Usuários");

        jLabel1.setText("Registro:");

        txtRegistro.setEnabled(false);

        jLabel2.setText("Número Conta:");

        jLabel3.setText("Agencia:");

        txtAgencia.setDocument(new LimitarTamanhoTextField(10));
        txtAgencia.setEnabled(false);

        txtNumeorConta.setEnabled(false);

        jLabel4.setText("Banco:");

        cmBanco.setEnabled(false);

        jLabel5.setText("Dia Vencimento:");

        sfDiaVencimento.setEnabled(false);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(txtRegistro, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel4)
                    .addComponent(cmBanco, javax.swing.GroupLayout.PREFERRED_SIZE, 304, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(txtNumeorConta, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE)
                        .addComponent(txtAgencia, javax.swing.GroupLayout.Alignment.LEADING))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(sfDiaVencimento, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap(899, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(7, 7, 7)
                .addComponent(txtRegistro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cmBanco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(7, 7, 7)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtAgencia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtNumeorConta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(sfDiaVencimento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 321, Short.MAX_VALUE))
        );

        jScrollPane1.setViewportView(jPanel1);

        jToolBar1.setFloatable(false);
        jToolBar1.setToolTipText("Cadastro Cliente");

        btNaoSeiAinda.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/internal/cad/document.png"))); // NOI18N
        btNaoSeiAinda.setText("");
        btNaoSeiAinda.setEnabled(false);
        btNaoSeiAinda.setFocusable(false);
        btNaoSeiAinda.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btNaoSeiAinda.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(btNaoSeiAinda);

        btNovo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/internal/cad/document_add.png"))); // NOI18N
        btNovo.setText("");
        btNovo.setFocusable(false);
        btNovo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btNovo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btNovoActionPerformed(evt);
            }
        });
        jToolBar1.add(btNovo);

        btSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/internal/cad/document_ok.png"))); // NOI18N
        btSalvar.setText("");
        btSalvar.setEnabled(false);
        btSalvar.setFocusable(false);
        btSalvar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btSalvar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSalvarActionPerformed(evt);
            }
        });
        jToolBar1.add(btSalvar);

        btEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/internal/cad/document_edit.png"))); // NOI18N
        btEditar.setText("");
        btEditar.setFocusable(false);
        btEditar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btEditar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btEditarActionPerformed(evt);
            }
        });
        jToolBar1.add(btEditar);

        btExcluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/internal/cad/document_error.png"))); // NOI18N
        btExcluir.setText("");
        btExcluir.setFocusable(false);
        btExcluir.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btExcluir.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btExcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btExcluirActionPerformed(evt);
            }
        });
        jToolBar1.add(btExcluir);

        btCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/internal/cad/document_delete.png"))); // NOI18N
        btCancelar.setText("");
        btCancelar.setEnabled(false);
        btCancelar.setFocusable(false);
        btCancelar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btCancelar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCancelarActionPerformed(evt);
            }
        });
        jToolBar1.add(btCancelar);
        jToolBar1.add(jSeparator1);

        btPrimeiro.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/internal/move/media_rewind.png"))); // NOI18N
        btPrimeiro.setText("");
        btPrimeiro.setFocusable(false);
        btPrimeiro.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btPrimeiro.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btPrimeiro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btPrimeiroActionPerformed(evt);
            }
        });
        jToolBar1.add(btPrimeiro);

        btAnterior.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/internal/move/media_step_back.png"))); // NOI18N
        btAnterior.setText("");
        btAnterior.setFocusable(false);
        btAnterior.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btAnterior.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btAnterior.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAnteriorActionPerformed(evt);
            }
        });
        jToolBar1.add(btAnterior);

        btProximo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/internal/move/media_step_forward.png"))); // NOI18N
        btProximo.setText("");
        btProximo.setFocusable(false);
        btProximo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btProximo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btProximo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btProximoActionPerformed(evt);
            }
        });
        jToolBar1.add(btProximo);

        btUltimo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/internal/move/media_fast_forward.png"))); // NOI18N
        btUltimo.setText("");
        btUltimo.setFocusable(false);
        btUltimo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btUltimo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btUltimo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btUltimoActionPerformed(evt);
            }
        });
        jToolBar1.add(btUltimo);
        jToolBar1.add(jSeparator2);

        btPesquisa.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/internal/print/document_view.png"))); // NOI18N
        btPesquisa.setText("");
        btPesquisa.setFocusable(false);
        btPesquisa.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btPesquisa.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btPesquisa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btPesquisaActionPerformed(evt);
            }
        });
        jToolBar1.add(btPesquisa);

        jXHyperlink12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/internal/print/printer.png"))); // NOI18N
        jXHyperlink12.setText("");
        jXHyperlink12.setFocusable(false);
        jXHyperlink12.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jXHyperlink12.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jXHyperlink12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jXHyperlink12ActionPerformed(evt);
            }
        });
        jToolBar1.add(jXHyperlink12);
        jToolBar1.add(jSeparator5);

        txtSair.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/internal/move/window_delete.png"))); // NOI18N
        txtSair.setText("");
        txtSair.setFocusable(false);
        txtSair.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        txtSair.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        txtSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtSairActionPerformed(evt);
            }
        });
        jToolBar1.add(txtSair);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 1138, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jSeparator4))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator4, javax.swing.GroupLayout.PREFERRED_SIZE, 5, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txtSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtSairActionPerformed
        try {

            con = Conexao.getCon();
            con.rollback();

            this.setVisible(false);

        } catch (SQLException e) {
            MessagemErro erro = new MessagemErro(new ErrorInfo("Erro no Sistema", "Não é Possível Continuar, Sistema Inativo", null, "Fatal", e, Level.WARNING, null), 1);
        }
    }//GEN-LAST:event_txtSairActionPerformed

    private void btPrimeiroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btPrimeiroActionPerformed
        if (ePesquisa == true) {
            capturaDados();
            index = 0;
            montarFields(index);
            ePesquisa = false;
        } else {
            index = 0;
            montarFields(index);
        }
    }//GEN-LAST:event_btPrimeiroActionPerformed

    private void btUltimoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btUltimoActionPerformed
        if (ePesquisa == true) {
            capturaDados();
            index = listaContaBancaria.size() - 1;
            montarFields(index);
            ePesquisa = false;
        } else {
            index = listaContaBancaria.size() - 1;
            montarFields(index);
        }
    }//GEN-LAST:event_btUltimoActionPerformed

    private void btProximoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btProximoActionPerformed
        if (ePesquisa == true) {
            capturaDados();
            if (index == (listaContaBancaria.size() - 1)) {
                index = 0;
                montarFields(index);
            } else {
                index = index + 1;
                montarFields(index);
            }
            ePesquisa = false;
        } else {
            if (index == (listaContaBancaria.size() - 1)) {
                index = 0;
                montarFields(index);
            } else {
                index = index + 1;
                montarFields(index);
            }
        }
    }//GEN-LAST:event_btProximoActionPerformed

    private void btAnteriorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAnteriorActionPerformed
        if (ePesquisa == true) {
            capturaDados();
            if (index > 0) {
                index = index - 1;
                montarFields(index);
            } else if (index == 0) {
                index = listaContaBancaria.size() - 1;
                montarFields(index);
            }
            ePesquisa = false;
        } else {
            if (index > 0) {
                index = index - 1;
                montarFields(index);
            } else if (index == 0) {
                index = listaContaBancaria.size() - 1;
                montarFields(index);
            }
        }
    }//GEN-LAST:event_btAnteriorActionPerformed

    private void btPesquisaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btPesquisaActionPerformed
        try {

            DialogPesquisaBanco pesquisa = new DialogPesquisaBanco(null, true);
            pesquisa.setVisible(true);

            if (pesquisa.getBanco() != null) {

                Banco u = pesquisa.getBanco();

//                listaBanco = new ArrayList<Banco>();
//                listaBanco.add(u);
                index = 0;
                montarFields(index);

                ePesquisa = true;

            }

        } catch (Exception e) {
            MessagemErro erro = new MessagemErro(new ErrorInfo("Erro no Sistema", "Não é Possível Continuar, Sistema Inativo", null, "Fatal", e, Level.WARNING, null), 1);
        }
    }//GEN-LAST:event_btPesquisaActionPerformed

    private void btNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btNovoActionPerformed

        habilitaBotao();
        habilitarTextFiel();
        limparTextField();

    }//GEN-LAST:event_btNovoActionPerformed

    private void btCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCancelarActionPerformed

        desabilitaBotao();
        desabilitarTextFiel();

        montarFields(0);

    }//GEN-LAST:event_btCancelarActionPerformed

    private void btSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSalvarActionPerformed
        try {

            boolean validacao = validarTextField();

            if (validacao == false) {

                ContaBancaria u = new ContaBancaria();

                Banco banco = (Banco) cmBanco.getSelectedItem();

                u.setBanco(banco);
                u.setNumeroConta(txtNumeorConta.getText());
                u.setAgencia(txtAgencia.getText());
                u.setDiaVencimento(sfDiaVencimento.getValue());

                if (editar == false) {
                    daoContaBancaria.inserir(u);
                } else if (editar == true) {
                    u.setIdContaBancaria(Integer.parseInt(txtRegistro.getText()));
                    daoContaBancaria.atualizar(u);
                    editar = false;
                }

                desabilitaBotao();
                desabilitarTextFiel();

                listaContaBancaria = daoContaBancaria.buscaTodos();

                index = listaContaBancaria.size() - 1;
                montarFields(index);

            }

        } catch (Exception e) {
            MessagemErro erro = new MessagemErro(new ErrorInfo("Erro no Sistema", "Não é Possível Continuar, Sistema Inativo", null, "Fatal", e, Level.WARNING, null), 1);
        }
    }//GEN-LAST:event_btSalvarActionPerformed

    private void jXHyperlink12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jXHyperlink12ActionPerformed
        try {
        } catch (Exception e) {
            MessagemErro erro = new MessagemErro(new ErrorInfo("Erro no Sistema", "Não é Possível Continuar, Sistema Inativo", null, "Fatal", e, Level.WARNING, null), 1);
        }
    }//GEN-LAST:event_jXHyperlink12ActionPerformed

    private void btEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btEditarActionPerformed
        try {

            if (Integer.parseInt(txtRegistro.getText()) > 0) {

                habilitaBotao();
                habilitarTextFiel();

                editar = true;
            }

        } catch (Exception e) {
            MessagemErro erro = new MessagemErro(new ErrorInfo("Erro no Sistema", "Não é Possível Continuar, Sistema Inativo", null, "Fatal", e, Level.WARNING, null), 1);
        }
    }//GEN-LAST:event_btEditarActionPerformed

    private void btExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btExcluirActionPerformed
        try {

            Object[] options = {"Confirmar", "Cancelar"};

            int i = JOptionPane.showOptionDialog(null,
                    "Excluir Banco?", "Excluir Banco",
                    JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,
                    options, options[0]);

            if (i == JOptionPane.YES_OPTION) {

                try {

                    Object[] options2 = {"Confirmar", "Cancelar"};

                    int j = JOptionPane.showOptionDialog(null,
                            "Você Tem Certeza que Quer Excluir esse Banco?", "Excluir?",
                            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,
                            options2, options[0]);

                    if (j == JOptionPane.YES_OPTION) {

                        daoContaBancaria.remover(listaContaBancaria.get(index));

                        capturaDados();
                        montarFields(0);
                    }

                } catch (Exception e) {
                    MessagemErro erro = new MessagemErro(new ErrorInfo("Erro no Sistema", "Não é Possível Continuar, Sistema Inativo", null, "Fatal", e, Level.WARNING, null), 1);
                }

            }

        } catch (Exception e) {
            MessagemErro erro = new MessagemErro(new ErrorInfo("Erro no Sistema", "Não é Possível Continuar, Sistema Inativo", null, "Fatal", e, Level.WARNING, null), 1);
        }
    }//GEN-LAST:event_btExcluirActionPerformed

    private void capturaDados() {
        try {

            listaContaBancaria = daoContaBancaria.buscaTodos();

        } catch (Exception e) {
            MessagemErro erro = new MessagemErro(new ErrorInfo("Erro no Sistema", "Não é Possível Continuar, Sistema Inativo", null, "Fatal", e, Level.WARNING, null), 1);
        }
    }

    private void habilitaBotao() {

        btNaoSeiAinda.setEnabled(false);
        btNovo.setEnabled(false);
        btSalvar.setEnabled(true);
        btEditar.setEnabled(false);
        btExcluir.setEnabled(false);
        btCancelar.setEnabled(true);

        btPrimeiro.setEnabled(false);
        btProximo.setEnabled(false);
        btUltimo.setEnabled(false);
        btAnterior.setEnabled(false);

    }

    private void desabilitaBotao() {

        btNaoSeiAinda.setEnabled(true);
        btNovo.setEnabled(true);
        btSalvar.setEnabled(false);
        btEditar.setEnabled(true);
        btExcluir.setEnabled(true);
        btCancelar.setEnabled(false);

        btPrimeiro.setEnabled(true);
        btProximo.setEnabled(true);
        btUltimo.setEnabled(true);
        btAnterior.setEnabled(true);
    }

    private void habilitarTextFiel() {

        cmBanco.setEnabled(true);
        txtNumeorConta.setEnabled(true);
        txtAgencia.setEnabled(true);
        sfDiaVencimento.setEnabled(true);

    }

    private void desabilitarTextFiel() {

        cmBanco.setEnabled(false);
        txtNumeorConta.setEnabled(false);
        txtAgencia.setEnabled(false);
sfDiaVencimento.setEnabled(false);
    }

    private void limparTextField() {

        txtRegistro.setText("");
        txtNumeorConta.setText("");
        txtAgencia.setText("");
        cmBanco.setSelectedIndex(-1);

    }

    private boolean validarTextField() {

        if ("".equals(txtNumeorConta.getText())) {
            txtNumeorConta.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 0, 51), 2));
            return true;
        } else {
            txtNumeorConta.setBorder(border);
        }

        if ("".equals(txtAgencia.getText())) {
            txtAgencia.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 0, 51), 2));
            return true;
        } else {
            txtAgencia.setBorder(border);
        }

        return false;

    }

    private void montarFields(int i) {

        try {

            if (listaContaBancaria.size() > 0) {

                ContaBancaria b = listaContaBancaria.get(i);

                txtRegistro.setText(String.valueOf(b.getIdContaBancaria()));
                txtNumeorConta.setText(b.getNumeroConta());
                txtAgencia.setText(b.getAgencia());
                sfDiaVencimento.setValue(b.getDiaVencimento());

            }

        } catch (Exception e) {
            MessagemErro erro = new MessagemErro(new ErrorInfo("Erro no Sistema", "Não é Possível Continuar, Sistema Inativo", null, "Fatal", e, Level.WARNING, null), 1);
        }

    }

    private void carregarCombo() {
        try {

            List<Banco> listaBanco = daoBanco.buscaTodos();

            cmBanco.setModel(new ComboBoxBancoModel(listaBanco));

            cmBanco.setSelectedIndex(1);

        } catch (Exception e) {
            MessagemErro erro = new MessagemErro(new ErrorInfo("Erro no Sistema", "Não é Possível Continuar, Sistema Inativo", null, "Fatal", e, Level.WARNING, null), 1);
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private org.jdesktop.swingx.JXHyperlink btAnterior;
    private org.jdesktop.swingx.JXHyperlink btCancelar;
    private org.jdesktop.swingx.JXHyperlink btEditar;
    private org.jdesktop.swingx.JXHyperlink btExcluir;
    private org.jdesktop.swingx.JXHyperlink btNaoSeiAinda;
    private org.jdesktop.swingx.JXHyperlink btNovo;
    private org.jdesktop.swingx.JXHyperlink btPesquisa;
    private org.jdesktop.swingx.JXHyperlink btPrimeiro;
    private org.jdesktop.swingx.JXHyperlink btProximo;
    private org.jdesktop.swingx.JXHyperlink btSalvar;
    private org.jdesktop.swingx.JXHyperlink btUltimo;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JComboBox cmBanco;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JToolBar.Separator jSeparator2;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JToolBar.Separator jSeparator5;
    private javax.swing.JToolBar jToolBar1;
    private org.jdesktop.swingx.JXHyperlink jXHyperlink12;
    private com.toedter.components.JSpinField sfDiaVencimento;
    private javax.swing.JTextField txtAgencia;
    private javax.swing.JTextField txtNumeorConta;
    private javax.swing.JTextField txtRegistro;
    private org.jdesktop.swingx.JXHyperlink txtSair;
    // End of variables declaration//GEN-END:variables

}
